﻿using System.Text.RegularExpressions;

namespace StockLib
{
    public class StockHelper
    {
        public static StockType GetStockType(Stock r)
        {
            if (r.Market == StockMarket.SHSE && Regex.IsMatch(r.Code, @"^(600|601)"))
                return StockType.shA;

            if (r.Market == StockMarket.SZSE && Regex.IsMatch(r.Code, @"^(000)"))
                return StockType.szA;

            if (r.Market == StockMarket.SHSE && Regex.IsMatch(r.Code, @"^(900)"))
                return StockType.shB;

            if (r.Market == StockMarket.SZSE && Regex.IsMatch(r.Code, @"^(200)"))
                return StockType.szB;

            if (r.Market == StockMarket.SHSE && Regex.IsMatch(r.Code, @"^(000|1[ABC])"))
                return StockType.shIndex;

            if (r.Market == StockMarket.SZSE && Regex.IsMatch(r.Code, @"^(399)"))
                return StockType.szIndex;

            if (r.Market == StockMarket.SZSE && Regex.IsMatch(r.Code, @"^(002)"))
                return StockType.szMse;

            if (r.Market == StockMarket.SZSE && Regex.IsMatch(r.Code, @"^(300)"))
                return StockType.szGem;

            return StockType.None;
        }
    }
}
